#ifndef WORKPIECEE616_H
#define WORKPIECEE616_H

#include <QDebug>


#include <string.h>
#include <thread>
#include <mutex>
#include <cstring>
#include <map>
#include <condition_variable>
#include "../MeasureWorkpiece.h"


#define     MAX_THREAD_NUM_E616        1

class WorkpieceE616 : public MeasureWorkpiece
{
public:
    WorkpieceE616();
    ~WorkpieceE616();

    bool SetTemplatePath(const std::string &path);
    bool SetStandardVal(const std::map<std::string, MeasureItemStandardVal> &standardValMap);
    void SetWorkpieceInfo(const std::string &modeName,
                          const std::string &workpieceType);
    void CacheData(const cv::Mat &image         ,
                   const QPoint &datumOffset    ,
                   int workpieceId              ,
                   int pictureId                ,
                   int channelId                ,
                   int fixtureId);

    void ProcessData();
    bool GetDatumPixelDistance(const QImage &img,
                               int fixtureId,
                               QMap<QString, float> &pixelDistance);
    void InitThread();
    void ExitThread();

private:
    void CorrectThreeD(std::map<std::string, float> &measRes, int fixtureId);
    float CalPosition(std::map<std::string, float> &measRes,
                      std::string strX, std::string strY);

private:
    QMap<int, WorkpieceInfo>                    m_workpieceMap;
    std::mutex                                  m_ioMutex;
    std::vector<std::thread>                    m_threadPool;
    bool                                        m_initThreadFinished_;          // 线程初始化完成标志
    std::atomic<bool>                           m_isSetPathFlag        ;

public:
    WorkpieceBuff                               m_workpieceBuff;
    bool                                        m_threadStopFlag;               // 线程停止标志

};

#endif // WORKPIECEE616_H
